//
//  MessageModel.m
//  WGFGlobalHouses
//
//  Created by waiguofang on 15/7/10.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//

#import "MessageModel.h"


@implementation MessageModel

-(instancetype)initWithDic:(NSDictionary*)dic{
    self = [super init];
    
    if (self) {
        
        self.messageTitle = [dic objectForKey:@"title"];
        self.messageSub = [dic objectForKey:@"sub"];
        NSString *msgType = [dic objectForKey:@"type"];
        if ([msgType isEqualToString:@"0"]) {
            [self setMessageType:MessageTypeSYS];
        }else if ([msgType isEqualToString:@"1"]){
            [self setMessageType:MessageTypeACTIVITY];
        }else if ([msgType isEqualToString:@"2"]){
            [self setMessageType:MessageTypeORDER];
        }else{
            [self setMessageType:MessageTypeSYS];
        }
        
        [self setMessageTime:[dic objectForKey:@"time"]];
        
        [self setMessageValue:[dic objectForKey:@"value"]];
        
    }
    
    return self;
}


-(NSDictionary*)toDic{
    
    
    if (self.messageSub==nil) {
        self.messageSub = @"";
    }
    
    if (self.messageTime==nil) {
        self.messageTime = @"";
    }
    
    if (self.messageValue==nil) {
        self.messageValue = @"0";
    }
    
    if (self.messageTitle==nil) {
        self.messageTitle = @"0";
    }
    
    
    NSMutableDictionary *dic = [NSMutableDictionary new];
    [dic setObject:self.messageTitle forKey:@"title"];
    [dic setObject:self.messageSub  forKey:@"sub"];
    
    NSString *type;
    if (self.messageType ==MessageTypeSYS) {
        type = @"0";
    }else if (self.messageType ==MessageTypeACTIVITY){
        type = @"1";
    }else if (self.messageType ==MessageTypeORDER){
        type = @"2";
    }else{
        type = @"0";
    }
    
    [dic setObject:type forKey:@"type"];
    [dic setObject:self.messageTime forKey:@"time"];
    [dic setObject:self.messageValue forKey:@"value"];
    
    return dic;
}

@end
